package com.filldream.fastboot.web.controller.common;

import com.filldream.fastboot.base.response.common.CaptchaDTO;
import com.filldream.fastboot.common.entity.B;
import com.filldream.fastboot.common.entity.R;
import com.filldream.fastboot.common.util.Assert;
import com.filldream.fastboot.core.manager.CheckCodeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/common/captcha")
@Api(tags = "Common-图形验证码")
public class CaptchaController {

    @ApiOperation(value = "获取图形验证码",notes = "account-账号，有可能是邮箱也有可能是手机号")
    @GetMapping("/get")
    public R<CaptchaDTO> get(){
        return R.autoSuccess(CheckCodeUtil.createVerifyCode());
    }

    @ApiOperation(value = "校验验证码",notes = "此处为了演示新增了一个方法，在实际的项目中可直接调用下面的方法即可")
    @GetMapping("/check")
    public B check(String code,String key){
        Assert.isEmpty(code, "你还没有输入验证码!");
        return CheckCodeUtil.checkCaptcha(code,key);
    }

}
